package ym.controller.patient;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import ym.pojo.EnteralNutritionPlan;
import ym.service.EnteralNutritionPlanService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 后台患者接口
 */
@CrossOrigin
@RestController
@RequestMapping("/back/enteralNutritionPlan")
public class EnteralNutritionPlanCon {
    @DubboReference
    private EnteralNutritionPlanService enteralNutritionPlanService;

    /**
     * 新增
     *
     * @param enteralNutritionPlan
     * @return 执行结果
     */
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('/patient')")//springsecurity鉴权注解
    public BaseResult add(EnteralNutritionPlan enteralNutritionPlan) {
        enteralNutritionPlanService.add(enteralNutritionPlan);
        return BaseResult.ok();
    }


    /**
     * 修改
     *
     * @param enteralNutritionPlan
     * @return 执行结果
     */
    @PostMapping("/update")
    public BaseResult update(EnteralNutritionPlan enteralNutritionPlan) {
        enteralNutritionPlanService.update(enteralNutritionPlan);
        return BaseResult.ok();
    }


    /**
     * 删除
     *
     * @param enteralNutritionPlanId
     * @return 执行结果
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Integer enteralNutritionPlanId) {
        enteralNutritionPlanService.delete(enteralNutritionPlanId);
        return BaseResult.ok();
    }


    /**
     * 根据id查询
     *
     * @param enteralNutritionPlanId
     * @return 查询结果
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer enteralNutritionPlanId) {
        EnteralNutritionPlan enteralNutritionPlan = enteralNutritionPlanService.findById(enteralNutritionPlanId);
        return BaseResult.ok(enteralNutritionPlan);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/findAll")
    public BaseResult findAll() {
        List<EnteralNutritionPlan> all = enteralNutritionPlanService.findAll();
        return BaseResult.ok(all);
    }

    /**
     * 分页查询
     *
     * @param search 搜索条件
     * @param page   当前页
     * @param size   每页大小
     * @return
     */
    @GetMapping("/search")
    @PreAuthorize("hasAnyAuthority('/patient')")
    public BaseResult search(String search, int page, int size) {
        Page<EnteralNutritionPlan> enteralNutritionPlanPage = enteralNutritionPlanService.search(search, page, size);
        return BaseResult.ok(enteralNutritionPlanPage);
    }

    /**
     * 根据NutritionPlanId分页查询
     *
     * @param nutritionPlanId
     * @param search
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/searchByNutritionPlanId")
    @PreAuthorize("hasAnyAuthority('/patient')")
    public BaseResult searchByNutritionPlanId(Integer nutritionPlanId, String search, int page, int size) {
        Page<EnteralNutritionPlan> enteralNutritionPlanPage = enteralNutritionPlanService.searchByNutritionPlanId(nutritionPlanId, search, page, size);
        return BaseResult.ok(enteralNutritionPlanPage);
    }
}
